from querier.esquerier import ElasticSearchQuerier
from classify.classify import cos_sim


class ImgSimQuerier(ElasticSearchQuerier):
    def __init__(self, classifier):
        super(ImgSimQuerier, self).__init__(None, None, None)
        self.classifier = classifier

    def _build_query(self, args):
        pass

    def _build_result(self, es_result, param):
        pass

    def search(self, args):
        base64_str = args.get('image_base64')
        base64_str_test = args.get('image_base64_test')

        f1 = self.classifier.classify(base64_str)[0]
        f2 = self.classifier.classify(base64_str_test)[0]
        sim = cos_sim(f1, f2)
        res = {'similarity': sim}
        return res
